package cn.com.generaldata.os.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;

import org.springframework.util.FileCopyUtils;

public class FileUtil {

	private final static SimpleDateFormat sfd = new SimpleDateFormat("SSS");
	private final static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");

	public static byte[] toBinary(File file) {
		if (file.exists()) {
			try {
				return FileCopyUtils.copyToByteArray(file);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public static byte[] toBinary(InputStream is) {
		if (is != null) {
			try {
				return FileCopyUtils.copyToByteArray(is);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	private final String[] industrys = new String[] { "1", "2", "3", "4", "5" };

	private Double[][] getAssociateValue(int industryNum, int total, Double[][] industryAddValues) {
		// 各产业相关度
		Double[][] industryAssociates = new Double[industrys.length][total + 1];

		for (int i = 0; i < industrys.length; i++) {
			if (i == industryNum) {
				continue;
			}
			for (int j = 0; j <= total; j++) {
				industryAssociates[i][j] = Math.abs(industryAddValues[industryNum][j] - industryAddValues[i][j]);
			}
		}
		return industryAssociates;

	}

	public String findServerPath() {
		String classPath = this.getClass().getClassLoader().getResource("/").getPath();
		try {
			classPath = URLDecoder.decode(classPath, "gb2312");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String[] strPath = classPath.split("/");
		String path = "";
		for (int i = 0; i < strPath.length; i++) {
			if (i > 0 && i <= 3) {
				path = path + strPath[i] + "/";
			}
		}
		return path;
	}

	public static void main(String[] args) {
		//总价
		BigDecimal totalPrice = new BigDecimal(345);
		//每百元积分
		int pointPercent = 10;
		//积分
		BigDecimal scale = (totalPrice.multiply(new BigDecimal(pointPercent))).divide(new BigDecimal(100)).setScale(0,
				BigDecimal.ROUND_HALF_UP);
		System.out.println(scale);
	}

	private static String replaceAll(String string, String string2) {
		// TODO Auto-generated method stub
		return null;
	}
}
